<%--
  Created by IntelliJ IDEA.
  User: 杨娇
  Date: 2025/7/3
  Time: 9:27
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 用户主页</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
            min-height: 100vh;
            display: flex;
        }

        /* 侧边栏样式 - 保持不变 */
        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
        }

        .sidebar-header .logo {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .sidebar-header .logo-icon {
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 18px;
            color: var(--light-color);
        }

        .sidebar-header h3 {
            font-size: 1.2rem;
            font-weight: 500;
            margin: 0;
        }

        .sidebar-header p {
            font-size: 0.8rem;
            opacity: 0.8;
            margin: 0;
        }

        .nav-menu {
            list-style: none;
            padding: 0 15px;
        }

        .nav-item {
            margin-bottom: 5px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            border-radius: 8px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .nav-link i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 16px;
        }

        .nav-link .badge {
            margin-left: auto;
            background-color: var(--light-color);
            color: var(--dark-color);
            font-size: 0.7rem;
            padding: 3px 6px;
        }

        .user-profile {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            padding: 0 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
        }

        .user-info:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 14px;
        }

        .user-name {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.7rem;
            opacity: 0.8;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .btn i {
            margin-right: 6px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
        }

        .btn-outline:hover {
            background-color: #f5f5f5;
        }

        /* 欢迎卡片 */
        .welcome-card {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
            border-radius: 12px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: var(--shadow);
            position: relative;
            overflow: hidden;
        }

        .welcome-card::before {
            content: '';
            position: absolute;
            top: -50px;
            right: -50px;
            width: 200px;
            height: 200px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
        }

        .welcome-card::after {
            content: '';
            position: absolute;
            bottom: -80px;
            right: -30px;
            width: 250px;
            height: 250px;
            background-color: rgba(255, 255, 255, 0.05);
            border-radius: 50%;
        }

        .welcome-content {
            position: relative;
            z-index: 1;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .welcome-text h2 {
            font-size: 1.8rem;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .welcome-text p {
            font-size: 1rem;
            opacity: 0.9;
            max-width: 600px;
        }

        .welcome-image {
            width: 120px;
            height: 120px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 40px;
        }

        /* 统计卡片样式 */
        .stats-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background-color: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: var(--shadow);
            transition: var(--transition);
            position: relative;
            overflow: hidden;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }

        .stat-card::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
        }

        .stat-card.charging-card::after {
            background: linear-gradient(to right, #4caf50, #81c784);
        }

        .stat-card.history-card::after {
            background: linear-gradient(to right, #ff9800, #ffb74d);
        }

        .stat-card.favorite-card::after {
            background: linear-gradient(to right, #028090, #00a896);
        }

        .stat-card.balance-card::after {
            background: linear-gradient(to right, #05668d, #028090);
        }

        .stat-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .stat-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
        }

        .charging-card .stat-icon {
            background: linear-gradient(135deg, #4caf50, #81c784);
        }

        .history-card .stat-icon {
            background: linear-gradient(135deg, #ff9800, #ffb74d);
        }

        .favorite-card .stat-icon {
            background: linear-gradient(135deg, #028090, #00a896);
        }

        .balance-card .stat-icon {
            background: linear-gradient(135deg, #05668d, #028090);
        }

        .stat-title {
            font-size: 0.9rem;
            color: #777;
            font-weight: 500;
        }

        .stat-value {
            font-size: 1.8rem;
            font-weight: 600;
            margin: 10px 0;
            color: var(--dark-color);
        }

        .stat-change {
            font-size: 0.8rem;
            display: flex;
            align-items: center;
        }

        .stat-change.positive {
            color: #4caf50;
        }

        .stat-change.negative {
            color: #f44336;
        }

        /* 快速操作 */
        .quick-actions {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            gap: 15px;
            margin-bottom: 30px;
        }

        .action-card {
            background-color: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: var(--shadow);
            transition: var(--transition);
            text-align: center;
            cursor: pointer;
        }

        .action-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }

        .action-icon {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: rgba(0, 168, 150, 0.1);
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 15px;
            color: var(--primary-color);
            font-size: 20px;
        }

        .action-title {
            font-size: 1rem;
            font-weight: 500;
            margin-bottom: 5px;
        }

        .action-desc {
            font-size: 0.8rem;
            color: #777;
        }

        /* 最近充电记录 */
        .recent-charges {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 20px;
            margin-bottom: 30px;
        }

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .section-title {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--dark-color);
        }

        .section-link {
            color: var(--primary-color);
            font-size: 0.9rem;
            text-decoration: none;
            display: flex;
            align-items: center;
        }

        .section-link i {
            margin-left: 5px;
            transition: var(--transition);
        }

        .section-link:hover i {
            transform: translateX(3px);
        }

        .charges-table {
            width: 100%;
            border-collapse: collapse;
        }

        .charges-table th,
        .charges-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #f0f0f0;
        }

        .charges-table th {
            background-color: #f8f9fa;
            font-weight: 500;
            color: #555;
            font-size: 0.9rem;
        }

        .charges-table tr:hover {
            background-color: #f9f9f9;
        }

        .charge-status {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.8rem;
            font-weight: 500;
        }

        .status-completed {
            background-color: #e8f5e9;
            color: #2e7d32;
        }

        .status-in-progress {
            background-color: #e3f2fd;
            color: #1565c0;
        }

        .status-failed {
            background-color: #ffebee;
            color: #c62828;
        }

        /* 附近充电站 */
        .nearby-stations {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 20px;
        }

        .station-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 20px;
        }

        .station-card {
            border: 1px solid #eee;
            border-radius: 8px;
            overflow: hidden;
            transition: var(--transition);
        }

        .station-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .station-image {
            height: 120px;
            background-color: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #ccc;
            font-size: 2rem;
        }

        .station-info {
            padding: 15px;
        }

        .station-name {
            font-size: 1.1rem;
            font-weight: 500;
            margin-bottom: 5px;
            display: flex;
            align-items: center;
        }

        .station-distance {
            font-size: 0.8rem;
            color: #777;
            margin-bottom: 10px;
        }

        .station-meta {
            display: flex;
            justify-content: space-between;
            font-size: 0.8rem;
            color: #555;
            margin-bottom: 15px;
        }

        .station-available {
            color: #4caf50;
            font-weight: 500;
        }

        .station-action {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .station-price {
            font-weight: 600;
            color: var(--dark-color);
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
                overflow: hidden;
            }

            .sidebar-header h3,
            .sidebar-header p,
            .nav-link span,
            .user-name,
            .user-role {
                display: none;
            }

            .sidebar-header {
                padding: 15px 10px;
            }

            .nav-link {
                justify-content: center;
                padding: 12px 0;
            }

            .nav-link i {
                margin-right: 0;
                font-size: 18px;
            }

            .main-content {
                margin-left: 70px;
            }
        }

        @media (max-width: 768px) {
            .stats-container {
                grid-template-columns: 1fr 1fr;
            }

            .quick-actions {
                grid-template-columns: 1fr 1fr;
            }

            .welcome-content {
                flex-direction: column;
                text-align: center;
            }

            .welcome-image {
                margin-top: 20px;
            }

            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }

        @media (max-width: 576px) {
            .stats-container {
                grid-template-columns: 1fr;
            }

            .quick-actions {
                grid-template-columns: 1fr;
            }

            .main-content {
                padding: 20px 15px;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div>
                <h3>绿能充</h3>
                <p>用户面板</p>
            </div>
        </div>
    </div>

    <ul class="nav-menu">
        <li class="nav-item">
            <a href="/user/home" class="nav-link active">
                <i class="fas fa-tachometer-alt"></i>
                <span>仪表盘</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/announcement/list" class="nav-link">
                <i class="fas fa-users"></i>
                <span>公告栏</span>
                <span class="badge">5</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/pile/list" class="nav-link">
                <i class="fas fa-charging-station"></i>
                <span>充电桩</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/map/mapDetail" class="nav-link">
                <i class="fas fa-list-alt"></i>
                <span>地图</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/center/personCenter/${user.id}" class="nav-link">
                <i class="fas fa-exclamation-triangle"></i>
                <span>个人中心</span>
                <span class="badge">3</span>
            </a>
        </li>
    </ul>

    <div class="user-profile">
        <div class="user-info">
            <div class="user-avatar">
                <i class="fas fa-user"></i>
            </div>
            <div>
                <div class="user-name">${user.username}</div>
                <div class="user-role">普通用户</div>
            </div>
        </div>
    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <div class="header">
        <div class="page-title">
            <h1>欢迎回来，${user.username}!</h1>
            <p>今天是<fmt:formatDate value="${now}" pattern="yyyy年MM月dd日 EEEE"/></p>
        </div>
        <div class="header-actions">
            <button class="btn btn-primary" id="refreshBtn">
                <i class="fas fa-refresh"></i> 刷新
            </button>
        </div>
    </div>

    <!-- 欢迎卡片 -->
    <div class="welcome-card">
        <div class="welcome-content">
            <div class="welcome-text">
                <h2>绿能充 - 让充电更简单</h2>
                <p>我们为您提供便捷的电动汽车充电服务，随时随地找到最近的充电桩，享受快速充电体验。</p>
            </div>
            <div class="welcome-image">
                <i class="fas fa-bolt"></i>
            </div>
        </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-container">
        <div class="stat-card charging-card">
            <div class="stat-header">
                <div class="stat-title">本月充电次数</div>
                <div class="stat-icon">
                    <i class="fas fa-bolt"></i>
                </div>
            </div>
            <div class="stat-value">12</div>
            <div class="stat-change positive">
                <i class="fas fa-arrow-up"></i> 20% 较上月
            </div>
        </div>

        <div class="stat-card history-card">
            <div class="stat-header">
                <div class="stat-title">累计充电时长</div>
                <div class="stat-icon">
                    <i class="fas fa-clock"></i>
                </div>
            </div>
            <div class="stat-value">36.5h</div>
            <div class="stat-change positive">
                <i class="fas fa-arrow-up"></i> 15% 较上月
            </div>
        </div>

        <div class="stat-card favorite-card">
            <div class="stat-header">
                <div class="stat-title">常用充电站</div>
                <div class="stat-icon">
                    <i class="fas fa-star"></i>
                </div>
            </div>
            <div class="stat-value">3</div>
            <div class="stat-change">
                <i class="fas fa-minus"></i> 持平
            </div>
        </div>

        <div class="stat-card balance-card">
            <div class="stat-header">
                <div class="stat-title">账户余额</div>
                <div class="stat-icon">
                    <i class="fas fa-wallet"></i>
                </div>
            </div>
            <div class="stat-value">¥${user.balance}</div>
            <div class="stat-change negative">
                <i class="fas fa-arrow-down"></i> 消费¥85.5
            </div>
        </div>
    </div>

    <!-- 快速操作 -->
    <div class="quick-actions">
        <div class="action-card" onclick="location.href='/user/pile/map'">
            <div class="action-icon">
                <i class="fas fa-map-marker-alt"></i>
            </div>
            <h3 class="action-title">
                <a href="${pageContext.request.contextPath}/user/map/mapDetail">查找充电桩</a>>
            </h3>
            <p class="action-desc">查看附近可用充电桩位置</p>
        </div>
        <div class="action-card" onclick="location.href='/user/pile/list'">
            <div class="action-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <h3 class="action-title">
                <a href="${pageContext.request.contextPath}/user/pile/list">充电桩列表</a>>
            </h3>
            <p class="action-desc">浏览所有充电桩信息</p>
        </div>
        <div class="action-card" onclick="location.href='/user/wallet/recharge'">
            <div class="action-icon">
                <i class="fas fa-money-bill-wave"></i>
            </div>
            <h3 class="action-title">
                <a href="${pageContext.request.contextPath}/user/balance/add">账户充值</a>>
            </h3>
            <p class="action-desc">为账户充值余额</p>
        </div>
    </div>

    <!-- 最近充电记录 -->
    <div class="recent-charges">
        <div class="section-header">
            <h2 class="section-title">最近充电记录</h2>
            <a href="${pageContext.request.contextPath}/user/record/list" class="section-link">查看全部 <i class="fas fa-chevron-right"></i></a>
        </div>
        <table class="charges-table">
            <thead>
            <tr>
                <th>订单号</th>
                <th>充电桩</th>
                <th>开始时间</th>
                <th>充电时长</th>
                <th>消费金额</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${recordList}" var="record" end="4">
                <tr>
                    <td>${record.orderNo}</td>  <!-- 使用orderNo而不是id -->
                    <td>${record.pileId}</td>  <!-- 这里应该是充电桩ID，如果需要显示名称，后端需要提供关联数据 -->
                    <td><fmt:formatDate value="${record.startTime}" pattern="MM-dd HH:mm"/></td>
                    <td>${record.duration}分钟</td>
                    <td>¥${record.amount}</td>
                    <td>
                        <c:choose>
                            <c:when test="${record.status == 'COMPLETED'}">
                                <span class="charge-status status-completed">已完成</span>
                            </c:when>
                            <c:when test="${record.status == 'CHARGING'}">
                                <span class="charge-status status-in-progress">充电中</span>
                            </c:when>
                            <c:when test="${record.status == 'CANCELLED'}">
                                <span class="charge-status status-failed">已取消</span>
                            </c:when>
                            <c:when test="${record.status == 'FAULT'}">
                                <span class="charge-status status-failed">故障中断</span>
                            </c:when>
                            <c:otherwise>
                                <span class="charge-status">${record.status}</span>
                            </c:otherwise>
                        </c:choose>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${empty recordList}">
                <tr>
                    <td colspan="6" style="text-align: center; padding: 20px;">暂无充电记录</td>
                </tr>
            </c:if>
            </tbody>
        </table>
    </div>

    <!-- 附近充电站 -->
    <div class="nearby-stations">
        <div class="section-header">
            <h2 class="section-title">附近充电站</h2>
            <a href="${pageContext.request.contextPath}/user/user/map/mapDetail" class="section-link">查看全部 <i class="fas fa-chevron-right"></i></a>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 刷新按钮功能
        const refreshBtn = document.getElementById('refreshBtn');
        if (refreshBtn) {
            refreshBtn.addEventListener('click', function() {
                this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 刷新中...';
                this.disabled = true;

                // 模拟刷新延迟
                setTimeout(() => {
                    location.reload();
                }, 1000);
            });
        }

        // 获取当前时间并更新
        function updateTime() {
            const now = new Date();
            const options = {
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                weekday: 'long',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit'
            };
            document.getElementById('current-time').textContent = now.toLocaleDateString('zh-CN', options);
        }

        // 初始化时间并每秒更新
        updateTime();
        setInterval(updateTime, 1000);

        // 其他交互功能可以在这里添加
    });
</script>
</body>
</html>